//
//  AY_BookTuijCell.m
//  AiYue
//
//  Created by boWen on 2023/10/17.
//

#import "AY_BookTuijCell.h"


@interface AY_BookTuijCell ()
//@property (nonatomic,strong) UIView * bg_View;//底部圆角
@property (strong,nonatomic) UIImageView * tuiJianImgView;
@property (strong,nonatomic) UILabel * tuiJianTitleLbl;
@property (strong,nonatomic) UILabel * tuiJianSubTitleLbl;
@property (strong,nonatomic) UILabel * authorLabel;//作者
@property (strong,nonatomic) UILabel *tipLabel;
@end

@implementation AY_BookTuijCell

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
    if ([super initWithStyle:style reuseIdentifier:reuseIdentifier]) {
        [self addAllSubviewsWithUI];
    }
    return self;
}


- (void)addAllSubviewsWithUI {
    self.selectionStyle = UITableViewCellSelectionStyleNone;
    self.contentView.backgroundColor = [UIColor whiteColor];
    
    self.tuiJianImgView = [AYTool createImageViewWithFrame:CGRectZero andImage:nil andBg:nil andRadius:YNUM(4) andAddSubView:self.contentView];
    [self.tuiJianImgView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.width.mas_equalTo((SCREEN_W - YNUM(90))/4);
        make.height.mas_equalTo(YNUM(92));
        make.left.top.equalTo(self.contentView);
    }];
    
    self.tipLabel = [AYTool createLabelWithFrame:CGRectZero andText:nil andTextColor:[UIColor whiteColor] andBgColor:nil andFont:YFont(10) andLines:1 andRadius:0 andAddSubView:self.tuiJianImgView];
    self.tipLabel.layer.masksToBounds = NO;
    self.tipLabel.textAlignment = NSTextAlignmentCenter;
    [self.tipLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.top.equalTo(self.tuiJianImgView);
        make.width.mas_equalTo(YNUM(28));
        make.height.mas_equalTo(YNUM(16));
    }];
    
    UIBezierPath *maskPath = [UIBezierPath bezierPathWithRoundedRect:CGRectMake(0, 0, YNUM(28), YNUM(16)) byRoundingCorners:UIRectCornerBottomLeft | UIRectCornerTopRight cornerRadii:CGSizeMake(YNUM(4), YNUM(4))];
    CAShapeLayer *maskLayer = [[CAShapeLayer alloc] init];
    maskLayer.frame = self.tipLabel.bounds;
    maskLayer.path = maskPath.CGPath;
    self.tipLabel.layer.mask = maskLayer;

    self.tuiJianTitleLbl = [AYTool createLabelWithFrame:CGRectZero andText:nil andTextColor:COLOR(@"#010101") andBgColor:nil andFont:[UIFont boldSystemFontOfSize:YNUM(16)] andLines:1 andRadius:0 andAddSubView:self.contentView];
    [self.tuiJianTitleLbl mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.tuiJianImgView.mas_top).offset(YNUM(2));
        make.left.equalTo(self.tuiJianImgView.mas_right).offset(YNUM(10));
        make.right.equalTo(self.contentView.mas_right).offset(YNUM(-16));
        make.height.mas_equalTo(YNUM(24));
    }];

    self.tuiJianSubTitleLbl = [AYTool createLabelWithFrame:CGRectZero andText:nil andTextColor:COLOR(@"#999999") andBgColor:nil andFont:YFont(12) andLines:2 andRadius:0 andAddSubView:self.contentView];
    [self.tuiJianSubTitleLbl mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.tuiJianTitleLbl.mas_bottom).offset(YNUM(6));
        make.left.equalTo(self.tuiJianTitleLbl.mas_left);
        make.right.equalTo(self.contentView.mas_right).offset(YNUM(-16));
    }];

    self.authorLabel = [AYTool createLabelWithFrame:CGRectZero andText:nil andTextColor:COLOR(@"#999999") andBgColor:nil andFont:YFont(12) andLines:1 andRadius:0 andAddSubView:self.contentView];
    [self.authorLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.bottom.equalTo(self.tuiJianImgView.mas_bottom);
        make.left.equalTo(self.tuiJianTitleLbl.mas_left);
        make.right.equalTo(self.contentView.mas_right).offset(YNUM(-16));
        make.height.mas_equalTo(YNUM(20));
    }];
}

- (void)setSubModel:(BookDecModel *)subModel {
    _subModel = subModel;
    [self.tuiJianImgView sd_setImageWithURL:[NSURL URLWithString:kStringUtils(_subModel.imagePic)] placeholderImage:YImage(@"placeholderImage")];
    self.tuiJianTitleLbl.text = kStringUtils(_subModel.name);
    self.tuiJianSubTitleLbl.text = kStringUtils(_subModel.info);
    self.authorLabel.text = [NSString stringWithFormat:@"%@・%@・%@章",kStringUtils(_subModel.author), kStringUtils(_subModel.categoryName), kStringUtils(_subModel.chapterNum)];
    [AYTool setBookStatusWithStatus:_subModel.status andLabel:self.tipLabel];
}


@end
